{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 线性模型和梯度下降\n",
    "这是神经网络的第一课，我们会学习一个非常简单的模型，线性回归，同时也会学习一个优化算法-梯度下降法，对这个模型进行优化。线性回归是监督学习里面一个非常简单的模型，同时梯度下降也是深度学习中应用最广的优化算法，我们将从这里开始我们的深度学习之旅"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 一元线性回归\n",
    "一元线性模型非常简单，假设我们有变量 $x_i$ 和目标 $y_i$，每个 i 对应于一个数据点，希望建立一个模型\n",
    "\n",
    "$$\n",
    "\\hat{y}_i = w x_i + b\n",
    "$$\n",
    "\n",
    "$\\hat{y}_i$ 是我们预测的结果，希望通过 $\\hat{y}_i$ 来拟合目标 $y_i$，通俗来讲就是找到这个函数拟合 $y_i$ 使得误差最小，即最小化\n",
    "\n",
    "$$\n",
    "\\frac{1}{n} \\sum_{i=1}^n(\\hat{y}_i - y_i)^2\n",
    "$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "那么如何最小化这个误差呢？\n",
    "\n",
    "这里需要用到**梯度下降**，这是我们接触到的第一个优化算法，非常简单，但是却非常强大，在深度学习中被大量使用，所以让我们从简单的例子出发了解梯度下降法的原理"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 梯度下降法\n",
    "在梯度下降法中，我们首先要明确梯度的概念，随后我们再了解如何使用梯度进行下降。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 梯度\n",
    "梯度在数学上就是导数，如果是一个多元函数，那么梯度就是偏导数。比如一个函数f(x, y)，那么 f 的梯度就是 \n",
    "\n",
    "$$\n",
    "(\\frac{\\partial f}{\\partial x},\\ \\frac{\\partial f}{\\partial y})\n",
    "$$\n",
    "\n",
    "可以称为 grad f(x, y) 或者 $\\nabla f(x, y)$。具体某一点 $(x_0,\\ y_0)$ 的梯度就是 $\\nabla f(x_0,\\ y_0)$。\n",
    "\n",
    "下面这个图片是 $f(x) = x^2$ 这个函数在 x=1 处的梯度\n",
    "\n",
    "![](https://ws3.sinaimg.cn/large/006tNc79ly1fmarbuh2j3j30ba0b80sy.jpg)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "梯度有什么意义呢？从几何意义来讲，一个点的梯度值是这个函数变化最快的地方，具体来说，对于函数 f(x, y)，在点 $(x_0, y_0)$ 处，沿着梯度 $\\nabla f(x_0,\\ y_0)$ 的方向，函数增加最快，也就是说沿着梯度的方向，我们能够更快地找到函数的极大值点，或者反过来沿着梯度的反方向，我们能够更快地找到函数的最小值点。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 梯度下降法\n",
    "有了对梯度的理解，我们就能了解梯度下降发的原理了。上面我们需要最小化这个误差，也就是需要找到这个误差的最小值点，那么沿着梯度的反方向我们就能够找到这个最小值点。\n",
    "\n",
    "我们可以来看一个直观的解释。比如我们在一座大山上的某处位置，由于我们不知道怎么下山，于是决定走一步算一步，也就是在每走到一个位置的时候，求解当前位置的梯度，沿着梯度的负方向，也就是当前最陡峭的位置向下走一步，然后继续求解当前位置梯度，向这一步所在位置沿着最陡峭最易下山的位置走一步。这样一步步的走下去，一直走到觉得我们已经到了山脚。当然这样走下去，有可能我们不能走到山脚，而是到了某一个局部的山峰低处。\n",
    "\n",
    "类比我们的问题，就是沿着梯度的反方向，我们不断改变 w 和 b 的值，最终找到一组最好的 w 和 b 使得误差最小。\n",
    "\n",
    "在更新的时候，我们需要决定每次更新的幅度，比如在下山的例子中，我们需要每次往下走的那一步的长度，这个长度称为学习率，用 $\\eta$ 表示，这个学习率非常重要，不同的学习率都会导致不同的结果，学习率太小会导致下降非常缓慢，学习率太大又会导致跳动非常明显，可以看看下面的例子\n",
    "\n",
    "![](https://ws2.sinaimg.cn/large/006tNc79ly1fmgn23lnzjg30980gogso.gif)\n",
    "\n",
    "可以看到上面的学习率较为合适，而下面的学习率太大，就会导致不断跳动\n",
    "\n",
    "最后我们的更新公式就是\n",
    "\n",
    "$$\n",
    "w := w - \\eta \\frac{\\partial f(w,\\ b)}{\\partial w} \\\\\n",
    "b := b - \\eta \\frac{\\partial f(w,\\ b)}{\\partial b}\n",
    "$$\n",
    "\n",
    "通过不断地迭代更新，最终我们能够找到一组最优的 w 和 b，这就是梯度下降法的原理。\n",
    "\n",
    "最后可以通过这张图形象地说明一下这个方法\n",
    "\n",
    "![](https://ws3.sinaimg.cn/large/006tNc79ly1fmarxsltfqj30gx091gn4.jpg)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "上面是原理部分，下面通过一个例子来进一步学习线性模型"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<torch._C.Generator at 0x7f53f805ecd0>"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import torch\n",
    "import numpy as np\n",
    "from torch.autograd import Variable\n",
    "\n",
    "torch.manual_seed(2017)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 读入数据 x 和 y\n",
    "x_train = np.array([[3.3], [4.4], [5.5], [6.71], [6.93], [4.168],\n",
    "                    [9.779], [6.182], [7.59], [2.167], [7.042],\n",
    "                    [10.791], [5.313], [7.997], [3.1]], dtype=np.float32)\n",
    "\n",
    "y_train = np.array([[1.7], [2.76], [2.09], [3.19], [1.694], [1.573],\n",
    "                    [3.366], [2.596], [2.53], [1.221], [2.827],\n",
    "                    [3.465], [1.65], [2.904], [1.3]], dtype=np.float32)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[<matplotlib.lines.Line2D at 0x7f539410ee48>]"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXcAAAD8CAYAAACMwORRAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4wLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvqOYd8AAAD8NJREFUeJzt3X+IHOd9x/HP5yRR++IQt9WRqJLuttCQkpjaShfXrqEYuwY3NXagLrhsXaekHIS0sYuh1DlwSeBKCsX9EUPMYqdR2sVNkE2qmritSAyJoVFYqbJsSYYYqjvLVaqzXct2N3Wr6Ns/ZoVOm7vs7N3uzuwz7xcss/Pco90vy95Hz81+Z9YRIQBAWqaKLgAAMHyEOwAkiHAHgAQR7gCQIMIdABJEuANAggh3AEgQ4Q4ACSLcASBBW4t64u3bt0etVivq6QFgIh06dOjViJjpN6+wcK/Vamq320U9PQBMJNtLeeZxWAYAEkS4A0CC+oa77ctsf9f2c7aP2f7MGnM+ZnvF9pHu7fdGUy4AII88x9zfkXRTRLxte5ukZ20/HRHf6Zn3lYj4/eGXCAAYVN9wj+yC7293d7d1b1wEHgBKLNcxd9tbbB+RdEbSgYg4uMa037B91PY+27vXeZx5223b7ZWVlU2UDQCTp9WSajVpairbtlqje65c4R4RP4yIayTtknSt7at6pvyjpFpE/IKkA5L2rvM4zYioR0R9ZqZvmyYAJKPVkubnpaUlKSLbzs+PLuAH6paJiDckPSPp1p7x1yLine7uo5J+cTjlAUAaFhakTufSsU4nGx+FPN0yM7av7N6/XNItkl7smbNj1e7tkk4Ms0gAmHTLy4ONb1aebpkdkvba3qLsP4OvRsRTtj8rqR0R+yV9yvbtks5Jel3Sx0ZTLgBMptnZ7FDMWuOjkKdb5qikPWuMP7jq/gOSHhhuaQCQjsXF7Bj76kMz09PZ+Chw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dezaaUMd9tWduz0REQ8VHQ9ZRERD0TEroioKftA7JsRwQpMUkR8X9LLtj/QHbpZ0vECSyqTZUnX2Z7u/m7dLD5s7rVf0j3d+/dI+ocCaxmKUoa7shXq3cpWpke6t48UXRRK7w8ktWwflXSNpD8tuJ5S6P41s0/SYUnPK/u9T+6MzLxsPy7pXyV9wPYp2x+X9DlJt9j+nrK/dD5XZI3DwBmqAJCgsq7cAQCbQLgDQIIIdwBIEOEOAAki3AEgQYQ7ACSIcAeABBHuAJCg/weHsaZQFbgrMwAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 画出图像\n",
    "import matplotlib.pyplot as plt\n",
    "%matplotlib inline\n",
    "\n",
    "plt.plot(x_train, y_train, 'bo')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 转换成 Tensor\n",
    "x_train = torch.from_numpy(x_train)\n",
    "y_train = torch.from_numpy(y_train)\n",
    "\n",
    "# 定义参数 w 和 b\n",
    "w = Variable(torch.randn(1), requires_grad=True) # 随机初始化\n",
    "b = Variable(torch.zeros(1), requires_grad=True) # 使用 0 进行初始化"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 构建线性回归模型\n",
    "x_train = Variable(x_train)\n",
    "y_train = Variable(y_train)\n",
    "\n",
    "def linear_model(x):\n",
    "    return x * w + b"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "y_ = linear_model(x_train)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "经过上面的步骤我们就定义好了模型，在进行参数更新之前，我们可以先看看模型的输出结果长什么样"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.legend.Legend at 0x7f53940f2320>"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXQAAAD8CAYAAABn919SAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4wLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvqOYd8AAAFuZJREFUeJzt3X9wVeWdx/HPNxjFKONayVIUk9AdyxZBEC4urlPLKipb7Cpj2ymTrWS2bWwpru103HGXP8pUsu04Xdidzo41VRYqqVuLrnVcp2qR0f5wqoFFi7AFBxMKoiC4FgkUSL77x7nBJCa5v+8597nv18yde+/J5Z5vjt5Pnvuc5zyPubsAAJWvJu4CAADFQaADQCAIdAAIBIEOAIEg0AEgEAQ6AASCQAeAQBDoABAIAh0AAnFGOXc2fvx4b2pqKucuAaDibd68+W13r8/0urIGelNTkzo7O8u5SwCoeGbWnc3rMna5mNnFZrbJzLab2atmdkd6+woz22dmW9O3TxZaNAAgf9m00E9J+oa7bzGzcZI2m9kz6Z+tdvfvlq48AEC2Mga6u++XtD/9+IiZ7ZB0UakLAwDkJqc+dDNrknS5pN9IukrSMjO7VVKnolb8O7kWcPLkSe3du1fHjx/P9Z9iBGPHjtWkSZNUW1sbdykAysiynQ/dzM6V9JykNnd/1MwmSHpbkku6W9JEd/+7Yf5dq6RWSWpoaJjd3T24b//111/XuHHjdMEFF8jMCvplILm7Dh06pCNHjmjy5MlxlwOgCMxss7unMr0uq3HoZlYr6RFJHe7+qCS5+1vu3uvufZJ+IOmK4f6tu7e7e8rdU/X1Hxx1c/z4ccK8iMxMF1xwAd94gKTo6JCamqSamui+o6Nku8rY5WJR0j4gaYe7rxqwfWK6f12SFknalm8RhHlxcTyBhOjokFpbpZ6e6Hl3d/Rckpqbi767bFroV0n6vKR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7P/GG2/0EydOuLv7V77yFV+xYoXPnz//9Gveeecdd3f/xCc+4S+99NLp7QOfS/Inn3zS3d1vvvlmv+666/zEiRO+detWnzFjhru7Hz161I8dO+bu7jt37vT+47Fp0yZfuHDh6fe97777/O6773Z39+PHj/vs2bN99+7d/sgjj/j8+fP91KlTvm/fPj/vvPP8Jz/5yYi/F1B11q93r6sbnA91ddH2Ciap07PI2Iqay6UU8+du3LhRmzdvPj03y7Fjx7RgwQLt3r1bt99+uxYuXKjrr78+4/uceeaZWrBggSRp+vTpOuuss1RbW6vp06erq6tLknTy5EktW7ZMW7du1ZgxY7Rz585h3+vpp5/WK6+8crp//N1339WuXbv0/PPPa/HixRozZowuvPBCXXPNNXn/3kCQRls0oUxT2MapsgK9BPPnuruWLFmib3/724O2t7W16amnntL3v/99Pfzww1qzZs2o71NbWyuzaOnVmpoanXXWWacfnzp1SpK0evVqTZgwQS+//LL6+vo0duzYEWv63ve+pxtuuGHQ9iefZBlXYFRlXsMzaSqrD70E8+dee+212rBhw+n+6MOHD6u7u1t9fX265ZZbtHLlSm3ZskWSNG7cOB05ciTvfb377ruaOHGiampq9OCDD6q3t3fY973hhht077336uTJk5KknTt36ujRo7r66qv14x//WL29vdq/f782bdqUdy1AkMq8hmfSVFYLvQTz506dOlUrV67U9ddfr76+PtXW1mrVqlVatGjR6cWi+1vvLS0t+vKXv6yzzz5bL7zwQs77Wrp0qW655Rb98Ic/1IIFC04vqnHZZZdpzJgxmjFjhlpaWnTHHXeoq6tLs2bNkrurvr5ejz32mBYtWqRnn31WU6dOVUNDw+mVlACktbVFAyUGdruUcA3PpGH63EBxXFG1OjpKu2hCDLKdPreyWugAkEkZ1/BMmsrqQwcAjCgRgV7Obp9qwPEEqlPsgT527FgdOnSIECoSd9ehQ4dGHBIJIFyx96FPmjRJe/fu1cGDB+MuJRhjx47VpEmT4i4DQJnFHui1tbWaPHly3GUAQMWLvcsFAFAcBDoABIJAB4BAEOgAEAgCHQACkTHQzexiM9tkZtvN7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S8VSXKBHffn378pqQJcRZTLIkLdDM7V9Ijkr7m7n+Iu564mdmNkg64++a4a0mgMyTNknSvu18u6agC+epcqHSf8E2K/uhdKOkcM/vbeKtKJo+G+gUx3C9RgW5mtYrCvMPdH427noS4StLfmFmXognQrjGz9fGWlBh7Je119/5vchsUBTyk+ZJed/eD7n5S0qOS/jLmmpLkLTObKEnp+wMx11MUiQl0MzNFfaE73H1V3PUkhbv/o7tPcvcmRSe1nnV3WlqS3P1NSb83synpTddK2h5jSUmyR9JcM6tLf7auFSeMB3pc0pL04yWSfhpjLUWTmEBX1BL9vKIW6Nb07ZNxF4XEu11Sh5m9ImmmpH+OuZ5ESH9r2SBpi6TfKvqsB3dlZDbM7CFJL0iaYmZ7zewLkr4j6Toz26Xo28x34qyxWLhSFAACkaQWOgCgAAQ6AASCQAeAQBDoABAIAh0AAkGgA0AgCHQACASBDgCB+H8yquTQlZrZqwAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.plot(x_train.data.numpy(), y_train.data.numpy(), 'bo', label='real')\n",
    "plt.plot(x_train.data.numpy(), y_.data.numpy(), 'ro', label='estimated')\n",
    "plt.legend()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**思考：红色的点表示预测值，似乎排列成一条直线，请思考一下这些点是否在一条直线上？**"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "这个时候需要计算我们的误差函数，也就是\n",
    "\n",
    "$$\n",
    "\\frac{1}{n} \\sum_{i=1}^n(\\hat{y}_i - y_i)^2\n",
    "$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 计算误差\n",
    "def get_loss(y_, y):\n",
    "    return torch.mean((y_ - y) ** 2)\n",
    "\n",
    "loss = get_loss(y_, y_train)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tensor(153.3520, grad_fn=<MeanBackward1>)\n"
     ]
    }
   ],
   "source": [
    "# 打印一下看看 loss 的大小\n",
    "print(loss)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "定义好了误差函数，接下来我们需要计算 w 和 b 的梯度了，这时得益于 PyTorch 的自动求导，我们不需要手动去算梯度，有兴趣的同学可以手动计算一下，w 和 b 的梯度分别是\n",
    "\n",
    "$$\n",
    "\\frac{\\partial}{\\partial w} = \\frac{2}{n} \\sum_{i=1}^n x_i(w x_i + b - y_i) \\\\\n",
    "\\frac{\\partial}{\\partial b} = \\frac{2}{n} \\sum_{i=1}^n (w x_i + b - y_i)\n",
    "$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 自动求导\n",
    "loss.backward()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tensor([161.0043])\n",
      "tensor([22.8730])\n"
     ]
    }
   ],
   "source": [
    "# 查看 w 和 b 的梯度\n",
    "print(w.grad)\n",
    "print(b.grad)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 更新一次参数\n",
    "w.data = w.data - 1e-2 * w.grad.data\n",
    "b.data = b.data - 1e-2 * b.grad.data"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "更新完成参数之后，我们再一次看看模型输出的结果"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.legend.Legend at 0x7f53940bc438>"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBOR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AJDcANAYAhuAAgMwQ0AgSG4ASAwBDcABIbgBoDAENwAEJj/B3whq/8kFWOXAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "y_ = linear_model(x_train)\n",
    "plt.plot(x_train.data.numpy(), y_train.data.numpy(), 'bo', label='real')\n",
    "plt.plot(x_train.data.numpy(), y_.data.numpy(), 'ro', label='estimated')\n",
    "plt.legend()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "从上面的例子可以看到，更新之后红色的线跑到了蓝色的线下面，没有特别好的拟合蓝色的真实值，所以我们需要在进行几次更新"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "epoch: 0, loss: 3.135772228240967\n",
      "epoch: 1, loss: 0.355089008808136\n",
      "epoch: 2, loss: 0.30295446515083313\n",
      "epoch: 3, loss: 0.30131959915161133\n",
      "epoch: 4, loss: 0.3006228804588318\n",
      "epoch: 5, loss: 0.2999469041824341\n",
      "epoch: 6, loss: 0.299274742603302\n",
      "epoch: 7, loss: 0.2986060082912445\n",
      "epoch: 8, loss: 0.2979407012462616\n",
      "epoch: 9, loss: 0.29727888107299805\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/home/bushuhui/.virtualenv/dl/lib/python3.5/site-packages/ipykernel_launcher.py:11: UserWarning: invalid index of a 0-dim tensor. This will be an error in PyTorch 0.5. Use tensor.item() to convert a 0-dim tensor to a Python number\n",
      "  # This is added back by InteractiveShellApp.init_path()\n"
     ]
    }
   ],
   "source": [
    "for e in range(10): # 进行 10 次更新\n",
    "    y_ = linear_model(x_train)\n",
    "    loss = get_loss(y_, y_train)\n",
    "    \n",
    "    w.grad.zero_() # 记得归零梯度\n",
    "    b.grad.zero_() # 记得归零梯度\n",
    "    loss.backward()\n",
    "    \n",
    "    w.data = w.data - 1e-2 * w.grad.data # 更新 w\n",
    "    b.data = b.data - 1e-2 * b.grad.data # 更新 b \n",
    "    print('epoch: {}, loss: {}'.format(e, loss.data[0]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.legend.Legend at 0x7f53942d5550>"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXcAAAD8CAYAAACMwORRAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4wLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvqOYd8AAAGcJJREFUeJzt3X+QVfWZ5/H3B+yIv0p3ocshAt2mJuUE+SW2FoyVhFVQRo3GNe7q9kTZiiGKGLOTdcqMVY5DZDKT2pLJ6JbKasaoxLGCWZelyE4SZaLmh9IwDaNgkDINtmFCi4YIgvx69o97G5tON/fc7nvvOffcz6vqVt977uGch1vdT3/7Od/vcxQRmJlZvoxIOwAzM6s8J3czsxxycjczyyEndzOzHHJyNzPLISd3M7MccnI3M8shJ3czsxxycjczy6Hj0jrxmDFjorW1Na3Tm5nVpbVr174dEc2l9kstube2ttLR0ZHW6c3M6pKkrUn2c1nGzCyHnNzNzHLIyd3MLIdSq7kP5MCBA3R3d7Nv3760Q8mNUaNGMW7cOJqamtIOxcxqKFPJvbu7m1NOOYXW1lYkpR1O3YsIdu7cSXd3N2eeeWba4ZhZDWWqLLNv3z5Gjx7txF4hkhg9erT/EjLLimXLoLUVRowofF22rGqnytTIHXBirzB/nmYZsWwZzJ8P779feL11a+E1QHt7xU+XqZG7mVlu3Xnnh4m91/vvF7ZXgZN7hc2bN4/ly5enHYaZZc22beVtH6a6Tu7VLl9FBIcP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QuzTj75ZG6//XbOPvtsZs+ezcsvv8ysWbP42Mc+xooVK4BCEv/kJz/J9OnTmT59Oj/72c8AuOOOO3jhhReYNm0aS5Ys4dChQ9x+++2cd955TJkyhYceeggo9L5ZuHAhZ511FrNnz2bHjh3D/r+bWU5ERCqPc889N/rbuHHj720bVEtLRCGtH/1oaUl+jAFs3LgxLr/88ti/f39ERNx8881x9913x+zZs4/s8+6770ZExKc//elYs2bNke19XwOxatWqiIj47Gc/G3PmzIn9+/dHZ2dnTJ06NSIi9uzZE3v37o2IiM2bN0fvZ7J69eq47LLLjhz3oYceiq9//esREbFv374499xz44033oinn346Zs+eHQcPHoy33norTj311Pje97434P/JzPKBwuLRkjk2czfITqxKPX+fffZZ1q5de6RfzN69e5k7dy5vvPEGt956K5dddhkXX3xxyeN85CMfYe7cuQBMnjyZ448/nqamJiZPnkxXVxcABw4cYOHChXR2djJy5Eg2b9484LF++MMfsmHDhiP19F27dvH666/z/PPPc9111zFy5Eg++tGPcuGFFw7r/25m+VG/ZZkq3bIqIrjhhhvo7Oyks7OTX/7yl3zrW99i/fr1zJo1iwcffJAbb7yx5HGampqQBMCIESM4/vjjjzw/ePAgAEuWLOH0009n/fr1dHR0sH///kFjuu+++47E9Ktf/SrRLxizhpfydbk01W9yr1LP34suuojly5cfqV+/8847bN26lcOHD3P11Vdzzz33sG7dOgBOOeUU3nvvvSGfa9euXYwdO5YRI0bw+OOPc+jQoQGPe8kll/DAAw9w4MABADZv3syePXv41Kc+xVNPPcWhQ4fYvn07q1evHnIsZrlTxety9aB+yzK9vX3vvLNQipkwoZDYh9nzd+LEidxzzz1cfPHFHD58mKamJu69916uuuqqIzfL/sY3vgEUph7edNNNnHDCCfz85z8v+1wLFizg6quv5rHHHmPu3LlHbhIyZcoURo4cydSpU5k3bx633XYbXV1dTJ8+nYigubmZZ555hquuuornnnuOiRMnMmHChCN3iTIzjn0vzhrdDSlNZbX8rSS3/K0df67WkEaMKIzY+5OgOFCrR0lb/tZvWcbM7Fi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0HHAi8OuU40lNRDxPYT1OX1fyYduU7wCfrWlQVZDJ5N6XpFbgHOCldCPJjL8D/hw4nHYgGXMm0AP8Q7Fk9bCkk9IOKgsi4i3gfwDbgO3Aroj4YbpRZc7pfVbZ/xtweprBVEKmk7ukk4Gnga9ExO/Sjidtki4HdkTE2rRjyaDjgOnAAxFxDrCHHPxpXQnF+vGVFH4BfhQ4SdKfphtVdkVhCmHdTyPMbHKX1EQhsS+LiO+nHU9GXABcIamLQl/9CyU9kW5ImdENdEdE7194yykke4PZwK8ioiciDgDfB/445Ziy5jeSxkKhVxawI+V4hi2TyV2SKNRON0XEvWnHkxUR8bWIGBcRrRQuiD0XER6BARHxb8Cbks4qbroI6H+3sEa1DZgh6cTiz9ZF+GJzfyuAG4rPbwD+T4qxVEQmkzuFEernKYxMe+/LemnaQVnm3Qosk7QBmAb8dcrxZELxr5nlwDrgXyn83OduRWZSkp4Efg6cJalb0heAvwHmSHqdwl86f5NmjJXgFapmZjmU1ZG7mZkNg5O7mVkOObmbmeWQk7uZWQ45uZuZ5ZCTu5lZDjm5m5nlkJO7mVkO/X8NtDpnjJPbvQAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "y_ = linear_model(x_train)\n",
    "plt.plot(x_train.data.numpy(), y_train.data.numpy(), 'bo', label='real')\n",
    "plt.plot(x_train.data.numpy(), y_.data.numpy(), 'ro', label='estimated')\n",
    "plt.legend()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "经过 10 次更新，我们发现红色的预测结果已经比较好的拟合了蓝色的真实值。\n",
    "\n",
    "现在你已经学会了你的第一个机器学习模型了，再接再厉，完成下面的小练习。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**小练习：**\n",
    "\n",
    "重启 notebook 运行上面的线性回归模型，但是改变训练次数以及不同的学习率进行尝试得到不同的结果"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 多项式回归模型"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "下面我们更进一步，讲一讲多项式回归。什么是多项式回归呢？非常简单，根据上面的线性回归模型\n",
    "\n",
    "$$\n",
    "\\hat{y} = w x + b\n",
    "$$\n",
    "\n",
    "这里是关于 x 的一个一次多项式，这个模型比较简单，没有办法拟合比较复杂的模型，所以我们可以使用更高次的模型，比如\n",
    "\n",
    "$$\n",
    "\\hat{y} = w_0 + w_1 x + w_2 x^2 + w_3 x^3 + \\cdots\n",
    "$$\n",
    "\n",
    "这样就能够拟合更加复杂的模型，这就是多项式模型，这里使用了 x 的更高次，同理还有多元回归模型，形式也是一样的，只是出了使用 x，还是更多的变量，比如 y、z 等等，同时他们的 loss 函数和简单的线性回归模型是一致的。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "首先我们可以先定义一个需要拟合的目标函数，这个函数是个三次的多项式"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "y = 0.90 + 0.50 * x + 3.00 * x^2 + 2.40 * x^3\n"
     ]
    }
   ],
   "source": [
    "# 定义一个多变量函数\n",
    "\n",
    "w_target = np.array([0.5, 3, 2.4]) # 定义参数\n",
    "b_target = np.array([0.9]) # 定义参数\n",
    "\n",
    "f_des = 'y = {:.2f} + {:.2f} * x + {:.2f} * x^2 + {:.2f} * x^3'.format(\n",
    "    b_target[0], w_target[0], w_target[1], w_target[2]) # 打印出函数的式子\n",
    "\n",
    "print(f_des)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "我们可以先画出这个多项式的图像"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.legend.Legend at 0x7f53910144e0>"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXwAAAD8CAYAAAB0IB+mAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4wLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvqOYd8AAAIABJREFUeJzt3Xl8VPW9//HXJxthCVsIiwQIuwqoQESo1muLVqvWtYLWXSt63Vtvq9Vbbau9V2tra9trLVWLWxFFq9atVupuWQKyCQTCmkSWsCQkhGwzn98fGfihZc1McmYy7+fjkcecOXNmvp8TwnvOfOd7vsfcHRERaf1Sgi5ARERahgJfRCRJKPBFRJKEAl9EJEko8EVEkoQCX0QkSSjwRUSSxEEHvpk9YWabzGzxHuu6mtk/zGxF5LZLZL2Z2W/NrMjMFprZqOYoXkREDt6hHOFPAU770ro7gBnuPhiYEbkP8E1gcORnEvCH6MoUEZFo2aGcaWtmecBr7j48cr8QOMnd15tZL+A9dx9qZn+MLE/98nb7e/1u3bp5Xl5ek3ZERCRZzZ07d7O75xxou7Qo2+mxR4hvAHpElnsDxXtsVxJZt9/Az8vLo6CgIMqSRESSi5mtPZjtYvalrTd+VDjkiXnMbJKZFZhZQVlZWazKERGRL4k28DdGunKI3G6KrC8F+uyxXW5k3b9x98nunu/u+Tk5B/xEIiIiTRRt4L8KXB5Zvhx4ZY/1l0VG64wFKg7Ufy8iIs3roPvwzWwqcBLQzcxKgHuA+4HnzexqYC0wIbL5G8DpQBFQDVzZ1ALr6+spKSmhpqamqS8he5GZmUlubi7p6elBlyIiLeSgA9/dL9rHQ+P3sq0DNzS1qD2VlJSQlZVFXl4eZhaLl0x67s6WLVsoKSmhf//+QZcjIi0k7s+0rampITs7W2EfQ2ZGdna2PjWJJJm4D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Apb883sbTM7LOiamsrMHjSzZZH9+auZdQ66pqYyswvM7DMzC5tZwo2oMLPTzKwwcgW3O4Kup6nM7Akz22Rmi4OuJVpm1sfM3jWzJZG/rVuCrqkpzCzTzGab2YLIfvy0WdtrTV06ZtbR3bdHlm8GjnT36wIuq0nM7BvAP929wcweAHD32wMuq0nM7AggDPwR+C93Lwi4pINmZqnAcuAUGicInANc5O5LAi2sCczsRKCKxosTDQ+6nmhELqjUy93nmVkWMBc4J9H+XaxxquH27l5lZunAR8AtkQtHxVyrOsLfFfYR7fniVbgSiru/7e4NkbszaZxiOiG5+1J3Lwy6jiYaAxS5+yp3rwOeo/GKbgnH3T8AtgZdRyy4+3p3nxdZrgSWso+LLMWzyFUBqyJ30yM/zZZbrSrwAczs52ZWDFwM3B10PTFyFfBm0EUkqYO+epsEw8zygJHArGAraRozSzWz+cAm4B/u3mz7kXCBb2bvmNnivfycDeDud7l7H+BZ4MZgq92/A+1LZJu7gAYa9yduHcy+iMSamXUAXgRu/dIn/ITh7iF3P4bGT/FjzKzZutuaaz78ZrOvK3DtxbM0zst/TzOWE5UD7YuZXQGcCYz3OP+y5RD+XRKNrt4WpyJ93i8Cz7r7S0HXEy13Lzezd4HTgGb5Yj3hjvD3x8wG73H3bGBZULVEy8xOA34InOXu1UHXk8TmAIPNrL+ZZQAX0nhFNwlQ5MvOx4Gl7v5Q0PU0lZnl7BqBZ2ZtaRwc0Gy51dpG6bwIDKVxRMha4Dp3T8ijMTMrAtoAWyKrZibwiKNzgd8BOUA5MN/dTw22qoNnZqcDvwFSgSfc/ecBl9QkZjYVOInGWRk3Ave4++OBFtVEZnYC8CGwiMb/7wB3uvsbwVV16MzsKOBJGv+2UoDn3f1nzdZeawp8ERHZt1bVpSMiIvumwBcRSRIKfBGRJKHAFxFJEgp8EZEkocAXEUkSCnwRkSShwBcRSRL/D/uFTGLU33onAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 画出这个函数的曲线\n",
    "x_sample = np.arange(-3, 3.1, 0.1)\n",
    "y_sample = b_target[0] + w_target[0] * x_sample + w_target[1] * x_sample ** 2 + w_target[2] * x_sample ** 3\n",
    "\n",
    "plt.plot(x_sample, y_sample, label='real curve')\n",
    "plt.legend()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "接着我们可以构建数据集，需要 x 和 y，同时是一个三次多项式，所以我们取了 $x,\\ x^2, x^3$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 构建数据 x 和 y\n",
    "# x 是一个如下矩阵 [x, x^2, x^3]\n",
    "# y 是函数的结果 [y]\n",
    "\n",
    "x_train = np.stack([x_sample ** i for i in range(1, 4)], axis=1)\n",
    "x_train = torch.from_numpy(x_train).float() # 转换成 float tensor\n",
    "\n",
    "y_train = torch.from_numpy(y_sample).float().unsqueeze(1) # 转化成 float tensor "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "torch.Size([61, 3])\n"
     ]
    }
   ],
   "source": [
    "print(x_train.size())"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "接着我们可以定义需要优化的参数，就是前面这个函数里面的 $w_i$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 定义参数和模型\n",
    "w = Variable(torch.randn(3, 1), requires_grad=True)\n",
    "b = Variable(torch.zeros(1), requires_grad=True)\n",
    "\n",
    "# 将 x 和 y 转换成 Variable\n",
    "x_train = Variable(x_train)\n",
    "y_train = Variable(y_train)\n",
    "\n",
    "def multi_linear(x):\n",
    "    return torch.mm(x, w) + b"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "我们可以画出没有更新之前的模型和真实的模型之间的对比"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.legend.Legend at 0x7f5390feddd8>"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXwAAAD8CAYAAAB0IB+mAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4wLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvqOYd8AAAIABJREFUeJzt3Xd4VVXWwOHfogkiUoRBJWAYRUdAmohBP7GBoCLYKMLYRkVUHCwjRRxE0VHBinVAEcUCDhZwBhQQFBVQyogUUYKN0MFBaiBlfX+sG4hATHLvTc4t632e89x+zrpE191nn73XFlXFOedc4isTdADOOedKhyd855xLEp7wnXMuSXjCd865JOEJ3znnkoQnfOecSxKe8J1zLkl4wnfOuSRR5IQvIqNFZIOILMn3XA0RmSYiK0K31UPPi4iMEJF0EflaRFqURPDOOeeKToo601ZE2gDbgVdVtXHouWHAL6r6sIgMAKqran8RuQC4FbgAOBV4SlVPLewYNWvW1NTU1PC+iXPOJakFCxZsUtVahb2vXFF3qKqzRCR1v6c7A2eF7r8CfAz0Dz3/qtqvyVwRqSYiR6nq2t87RmpqKvPnzy9qSM455wAR+ako74u0D792viS+Dqgdul8HWJXvfRmh5w4gIr1EZL6IzN+4cWOE4TjnnCtI1C7ahlrzxa7EpqojVbWlqrasVavQMxLnnHNhijThrxeRowBCtxtCz68G6uZ7X0roOeeccwEpch9+ASYBVwMPh24n5nu+j4iMwy7a/lpY/31BsrKyyMjIIDMzM8JQXTgqVqxISkoK5cuXDzoU51yEipzwReRN7AJtTRHJAO7FEv1bInId8BPQNfT2ydgInXRgJ3BtuAFmZGRQpUoVUlNTEZFwd+PCoKps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fNJ5gFXqOqyQAMLg4i0AbYDr6pq46DjiYSIHAUcpaoLRaQKsAC4ON7+LiIiQGVV3S4i5YHPgL6qOreQj4YloVr4eck+pDIQt79mqjpVVbNDD+diQ1vjkqp+o6rhTqgLWisgXVW/V9U9wDhsJnncUdVZwC9BxxENqrpWVReG7m8DvqGAyZ2xTM320MPyoa3E8lZCJXwAEXlQRFYBPYHBQccTJX8BpgQdRJKqA6zK97jAWeMuGCKSCjQHvgg2kvCISFkR+QrYAExT1RL7HnGX8EVkuogsOcjWGUBVB6lqXeB1oE+w0f6+wr5L6D2DsKGtrwcXaeGK8l2cizYROQx4G7htvzP8uKGqOaraDDuLbyUiJdbdFneLmP/ezN/9vA5MBu4twXAiUth3EZFrgI7AuRrjF1uK8XeJNz5rPEaF+rzfBl5X1XeCjidSqrpFRGYCHYASubAedy383yMiDfI97AwsDyqWSIlIB6Af0ElVdwYdTxKbBzQQkfoiUgEr+z0p4JiSXuhi50vAN6r6eNDxhEtEauWNwBORStjggBLLW4k2Sudt4ARsRMhPQG9VjcvWmIikA4cAm0NPzY3jEUeXAE8DtYAtwFeqGjeL4ojIBcCTQFlgtKo+GHBIYRGRN4GzsHpX64F7VfWlQIMKk4j8H/ApsBj7/x3gblWdHFxUxSciTYBXsP+2ygBvqer9JXa8REr4zjnnCpZQXTrOOecK5gnfOeeShCd855xLEp7wnXMuSXjCd865JOEJ3znnkoQnfOecSxKe8J1zLkn8Pwp8Wr9tuo1BAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 画出更新之前的模型\n",
    "y_pred = multi_linear(x_train)\n",
    "\n",
    "plt.plot(x_train.data.numpy()[:, 0], y_pred.data.numpy(), label='fitting curve', color='r')\n",
    "plt.plot(x_train.data.numpy()[:, 0], y_sample, label='real curve', color='b')\n",
    "plt.legend()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "可以发现，这两条曲线之间存在差异，我们计算一下他们之间的误差"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tensor(413.9844, grad_fn=<MeanBackward1>)\n"
     ]
    }
   ],
   "source": [
    "# 计算误差，这里的误差和一元的线性模型的误差是相同的，前面已经定义过了 get_loss\n",
    "loss = get_loss(y_pred, y_train)\n",
    "print(loss)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 自动求导\n",
    "loss.backward()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tensor([[ -34.1391],\n",
      "        [-146.6133],\n",
      "        [-215.9149]])\n",
      "tensor([-27.0838])\n"
     ]
    }
   ],
   "source": [
    "# 查看一下 w 和 b 的梯度\n",
    "print(w.grad)\n",
    "print(b.grad)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 更新一下参数\n",
    "w.data = w.data - 0.001 * w.grad.data\n",
    "b.data = b.data - 0.001 * b.grad.data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.legend.Legend at 0x7f5390fb8a20>"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXwAAAD8CAYAAAB0IB+mAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4wLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvqOYd8AAAIABJREFUeJzt3Xd4VNXWwOHfI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+UyAR0gZ+I45z7GtjhdRzB4Jzb5Jxb4r+/F1hNBK654dQ+/8MS/i1keSuqEj6AiAwWkQ1AN2Cg1/EEya3Ap14HEaNsMZ8wJyK1gEbAQm8jKRwRiRORH4GtwGznXMjeR8QlfBGZIyIrctnaATjnBjjnqgPjgd7eRntseb0X/z4D0Iqj472LNG/5eS/GBJuIlAUmA/cf8Q0/Yjjnspxz56Lf4puKSMi62wItj1zkjrUgyxHGA58AT4QwnIDk9V5E5BagDdDShfnFlgL8XSJNvhfzMUXL3+c9GRjvnPvQ63gC5ZzbJSJfAFcCIbmwHnEt/GMRkTo5HrYDfvYqlkCJyJVAX6Ctcy7V63hi2A9AHRGpLSIlgc7oAj/GQ/6LnW8Bq51zI7yOp7BEpEr2CDwROQ4dHBCyvBVto3QmA2ehI0LWA3c55yKyNSYi64BSwHb/UwsieMRRe+AloAqwC/jROdfa26jyT0SuBp4H4oAx/rUeIo6IvAdcglZl3AI84Zx7y9OgCklELgK+AZaj/98BHnXOfeJdVAUnIg2Acei/rWLA+865p0J2vmhK+MYYY44uqrp0jDHGHJ0lfGOMiRGW8I0xJkZYwjfGmBhhCd8YY2KEJXxjjIkRlvCNMSZGWMI3xpgY8f+eanIDcJ315QAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 画出更新一次之后的模型\n",
    "y_pred = multi_linear(x_train)\n",
    "\n",
    "plt.plot(x_train.data.numpy()[:, 0], y_pred.data.numpy(), label='fitting curve', color='r')\n",
    "plt.plot(x_train.data.numpy()[:, 0], y_sample, label='real curve', color='b')\n",
    "plt.legend()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "因为只更新了一次，所以两条曲线之间的差异仍然存在，我们进行 100 次迭代"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "epoch 20, Loss: 73.67843\n",
      "epoch 40, Loss: 17.97095\n",
      "epoch 60, Loss: 4.94101\n",
      "epoch 80, Loss: 1.87171\n",
      "epoch 100, Loss: 1.12812\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/home/bushuhui/.virtualenv/dl/lib/python3.5/site-packages/ipykernel_launcher.py:14: UserWarning: invalid index of a 0-dim tensor. This will be an error in PyTorch 0.5. Use tensor.item() to convert a 0-dim tensor to a Python number\n",
      "  \n"
     ]
    }
   ],
   "source": [
    "# 进行 100 次参数更新\n",
    "for e in range(100):\n",
    "    y_pred = multi_linear(x_train)\n",
    "    loss = get_loss(y_pred, y_train)\n",
    "    \n",
    "    w.grad.data.zero_()\n",
    "    b.grad.data.zero_()\n",
    "    loss.backward()\n",
    "    \n",
    "    # 更新参数\n",
    "    w.data = w.data - 0.001 * w.grad.data\n",
    "    b.data = b.data - 0.001 * b.grad.data\n",
    "    if (e + 1) % 20 == 0:\n",
    "        print('epoch {}, Loss: {:.5f}'.format(e+1, loss.data[0]))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "可以看到更新完成之后 loss 已经非常小了，我们画出更新之后的曲线对比"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.legend.Legend at 0x7f5390f019e8>"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXwAAAD8CAYAAAB0IB+mAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4wLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvqOYd8AAAIABJREFUeJzt3Xd4VNXWx/HvSgOkSBWQAEFBpIZuwC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VkmYhs8f7d6u92TdkhIgVFZK2I/OD9HM8EtL38NKQjIsVU9Xfv/YeBmqra2+WyskVEbgKWqmqaiIwBUNVBLpeVLSJSA/AArwH/VdVYl0vKNBEJBX4GbsS5yM93wB2qusXVwrJBRJoDCcBMVa3tdj2+EJHyQHlVXS8iRYF1wK157c9FnMsFFlbVBBEJB74B+qvq6kC0l696+H+EvVdhIM/+NlPVRaqa5n24GucykXmSqm5V1Z/criObmgA7VHWXqqYAs4EOLteULaq6Ajjmdh3+oKoHVXW99/5JYCtQwd2qsk4dCd6H4d4tYLmVrwIfQERGi8g+oDswzO16/OQ/wGduFxGkKgD7MjyOIw8GS34mIlFAfWCNu5Vkj4iEisgG4AjwpaoG7HPkucAXkcUisvksWwcAVR2qqhWB94C+7lZ7fhf6LN5jhgJpOJ8n18rMZzHG30SkCDAfGPC3f+HnGaqarqr1cP4V30REAjbcFqhr2gaMqrbM5KHv4Vxb9+kAluOTC30WEbkXaAu00Fz+ZUsW/lzymv1AxQyPI737jMu8Y97zgfdU9UO36/GVqh4XkWVAayAgX6znuR7++YhItQwPOwDb3KrFVyLSGhgItFfVRLfrCWLfAdVEpIqIRABdgYUu1xT0vF92vglsVdXxbteTXSJS5o8ZeCJSCGdyQMByK7/N0pkPVMeZEbIH6K2qebI3JiI7gALAUe+u1Xl4xtFtwEtAGeA4sEFVW7lbVeaJSBtgIhAKvKWqo10uKVtEZBZwHc6qjIeBp1X1TVeLyiYR+RfwNbAJ5/93gCdU9VP3qso6EakLzMD5uxUCzFXVEQFrLz8FvjHGmHPLV0M6xhhjzs0C3xhjgoQFvjHGBAkLfGOMCRIW+MYYEyQs8I0xJkhY4BtjTJCwwDfGmCDx/11baAG1R405AAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 画出更新之后的结果\n",
    "y_pred = multi_linear(x_train)\n",
    "\n",
    "plt.plot(x_train.data.numpy()[:, 0], y_pred.data.numpy(), label='fitting curve', color='r')\n",
    "plt.plot(x_train.data.numpy()[:, 0], y_sample, label='real curve', color='b')\n",
    "plt.legend()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "可以看到，经过 100 次更新之后，可以看到拟合的线和真实的线已经完全重合了"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "**小练习：上面的例子是一个三次的多项式，尝试使用二次的多项式去拟合它，看看最后能做到多好**\n",
    "\n",
    "**提示：参数 `w = torch.randn(2, 1)`，同时重新构建 x 数据集**"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
